package com.ruoyi.web.controller.system;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Gen2;
import com.ruoyi.system.service.IGen2Service;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代码Controller
 * 
 * @author ruoyi
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/system/gen2")
public class Gen2Controller extends BaseController
{
    @Autowired
    private IGen2Service gen2Service;

    /**
     * 查询代码列表
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:list')")
    @GetMapping("/list")
    public TableDataInfo list(Gen2 gen2)
    {
        startPage();
        List<Gen2> list = gen2Service.selectGen2List(gen2);
        return getDataTable(list);
    }

    /**
     * 导出代码列表
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:export')")
    @Log(title = "代码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Gen2 gen2)
    {
        List<Gen2> list = gen2Service.selectGen2List(gen2);
        ExcelUtil<Gen2> util = new ExcelUtil<Gen2>(Gen2.class);
        util.exportExcel(response, list, "代码数据");
    }

    /**
     * 获取代码详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:query')")
    @GetMapping(value = "/{columnId}")
    public AjaxResult getInfo(@PathVariable("columnId") Long columnId)
    {
        return success(gen2Service.selectGen2ByColumnId(columnId));
    }

    /**
     * 新增代码
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:add')")
    @Log(title = "代码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Gen2 gen2)
    {
        return toAjax(gen2Service.insertGen2(gen2));
    }

    /**
     * 修改代码
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:edit')")
    @Log(title = "代码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Gen2 gen2)
    {
        return toAjax(gen2Service.updateGen2(gen2));
    }

    /**
     * 删除代码
     */
    @PreAuthorize("@ss.hasPermi('system:gen2:remove')")
    @Log(title = "代码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{columnIds}")
    public AjaxResult remove(@PathVariable Long[] columnIds)
    {
        return toAjax(gen2Service.deleteGen2ByColumnIds(columnIds));
    }
}
